package com.mxx.common.payment;

import com.mxx.common.conv.JacksonConverter;
import com.mxx.common.payment.ali.AliPaymentParameter;
import com.mxx.common.payment.ali.AliPrepaymentResponse;
import com.mxx.common.payment.ali.DefaultAliPaymentHandler;
import com.mxx.common.payment.apple.ApplePaymentParameter;
import com.mxx.common.payment.apple.ApplePrepaymentResponse;
import com.mxx.common.payment.apple.DefaultApplePaymentHandler;
import com.mxx.common.payment.wechat.DefaultWeChatPaymentHandler;
import com.mxx.common.payment.wechat.WeChatPaymentParameter;
import com.mxx.common.payment.wechat.WeChatPrepaymentResponse;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Auther: Mr. Zeng
 * @Date: 2020/8/14 17:06
 * @Description: 暂无描述
 */
@Configuration
public class LoadPaymentConfiguration {
    @Bean
    @ConditionalOnBean(AliPaymentParameter.class)
    @ConditionalOnMissingBean(DefaultAliPaymentHandler.class)
    public PaymentHandler<AliPrepaymentResponse> aliPaymentHandler(AliPaymentParameter aliPaymentParameter) {
        return new DefaultAliPaymentHandler(aliPaymentParameter);
    }

    @Bean
    @ConditionalOnBean(WeChatPaymentParameter.class)
    @ConditionalOnMissingBean(DefaultWeChatPaymentHandler.class)
    public PaymentHandler<WeChatPrepaymentResponse> weChatPaymentHandler(WeChatPaymentParameter weChatPaymentParameter, JacksonConverter jacksonConverter) {
        return new DefaultWeChatPaymentHandler(weChatPaymentParameter, jacksonConverter);
    }

    @Bean
    @ConditionalOnBean(ApplePaymentParameter.class)
    @ConditionalOnMissingBean(DefaultApplePaymentHandler.class)
    public PaymentHandler<ApplePrepaymentResponse> applePaymentHandler(ApplePaymentParameter applePaymentParameter) {
        return new DefaultApplePaymentHandler(applePaymentParameter);
    }

    @Bean
    @ConditionalOnBean(PaymentHandler.class)
    public ApplicationTradeContext applicationTradeContext() {
        return new ApplicationTradeContext();
    }

}
